﻿#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 定时改变动画机变量
/// 更抽象的写法。用一个类存储每个时间点做的事，基类OnTimeEvent.一个成员float onTime
/// 时间执行基类DoOnTime.字段为OnTimeEvent[].到时执行
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class OnTimer: NextRunner
{
    public float[] times;

	protected virtual IEnumerator OnTimeRun()
    {
        if (times.Length == 0) yield break;
        for (int i = 0; i < times.Length; i++)
        {
            yield return new WaitForSeconds(times[i]);
            DoOnTime(i);
        }
    }

    protected virtual void Start()
    {
        StartCoroutine(OnTimeRun());
    }

    /// <summary>
    /// 在索引时间点到时执行。
    /// </summary>
    /// <param name="i">时间下标</param>
    public abstract void DoOnTime(int i);
}


